// pages/index/index.js
const locationMap = {
  '西湖区': '发现西湖边的人气美食',
  '余杭区': '未来科技城工作餐精选',
  '默认': '欢迎探索杭州美食地图'
}

Page({
  data: {
    activeTab: 0,
    welcomeMessage: '欢迎回来',
    currentLocation: '定位中...',
    liveList: [
      {
        id: 1,
        cover: '/static/images/live (1).png',
        shopName: '轻食沙拉厨房',
        viewers: 1280,
        duration: 45
      },
      {
        id: 2,
        cover: '/static/images/live (1).png',
        shopName: '烧烤厨房',
        viewers: 280,
        duration: 25
      },
      // 更多直播数据...
    ],
    banners: [
      { id: 1, img: '/static/images/banner.png' },
      { id: 2, img: '/static/images/banner.png' }
    ],
    shopList: [
      {
        id: 1,
        logo: '/static/images/shop.png',
        name: '元气早餐铺',
        rating: 4.9,
        sales: 1500,
        deliveryFee: 3,
        deliveryTime: 30,
        tags: ['现磨豆浆', '三明治']
      },
      // 更多商家数据...
    ]
  },

  onLoad() {
    this.getLocation()
  },

  // 获取定位
  getLocation() {
    wx.getLocation({
      type: 'gcj02',
      success: (res) => {
        const district = this.parseDistrict(res) // 模拟解析行政区
        this.setData({
          currentLocation: `杭州·${district}`,
          welcomeMessage: locationMap[district] || locationMap['默认']
        })
      },
      fail: () => {
        this.setData({
          currentLocation: '杭州·未知区域',
          welcomeMessage: locationMap['默认']
        })
      }
    })
  },

  // 模拟行政区解析
  parseDistrict() {
    return ['西湖区', '余杭区'][Math.floor(Math.random()*2)] // 随机返回模拟数据
  },

  // 切换模块
  switchTab(e) {
    this.setData({ activeTab: e.currentTarget.dataset.tab })
  },

  // 跳转搜索
  goSearch() {
    wx.navigateTo({ url: '/pages/search/search' })
  }
})